<div class="form_content">
    <div class="f-title">
        是否启用
    </div>
    <div class="f-input">
        <label class="am-radio-inline">
            <input type="radio" name="enable" value="0" data-am-ucheck checked> 启用 </label>
        <label class="am-radio-inline">
            <input type="radio" name="enable" value="1" data-am-ucheck> 禁用</label>
    </div>
    <div class="clear"></div>

    <div class="f-title">
        支付宝名字
    </div>
    <div class="f-input">
        <input type="text" id="name" class="am-form-field" placeholder="输入支付宝姓名" required/>
    </div>
    <div class="clear"></div>

    <div class="f-title">
        支付宝账号
    </div>
    <div class="f-input">
        <input type="text" id="account" class="am-form-field" placeholder="输入支付宝账户" required/>
    </div>
    <div class="clear"></div>

    <div class="f-title">
        二维码
    </div>
    <div class="f-input">
        <img src="" class="qrcode"/>
        <input type="file" class="qrcode" data-url="/tephra/ctrl-http/upload" multiple>
    </div>
    <div class="clear"></div>

    <div class="f-title">
        最低充值限额
    </div>
    <div class="f-input">
        <input type="text" id="min" class="am-form-field" placeholder="输入最低充值限额，元" required/>
    </div>
    <div class="clear"></div>

    <div class="f-title">
        最高充值限额
    </div>
    <div class="f-input">
        <input type="text" id="max" class="am-form-field" placeholder="输入最高充值限额，元" required/>
    </div>
    <div class="clear"></div>

    <div class="button2">
        <button class="am-btn am-btn-primary btn-save">保存</button>
    </div>
</div>
<style type="text/css">
    img.qrcode {
        width: 80px;
        height: 80px;
        border: 1px solid black;
    }
</style>

<script>
    var charges = {};
    GroupUtil.init(false, function() {
        charges = GroupUtil.queryChargeTypes(true);
        var data = charges.alipay;
        if (!data) {
            charges.alipay = {};
            return;
        }

        // 填入数据
        if (data.enable) $("input:radio[value='0']").prop("checked", "checked");
        else $("input:radio[value='1']").prop("checked", "checked");

        $("img.qrcode").attr("src", data.qrcode);
        $("#account").val(data.account || '');
        $("#name").val(data.name || '');
        $("#min").val(data.min || 0);
        $("#max").val(data.max || 0);
    });

    $(".btn-save").click(function() {
        charges.alipay.account = $("#account").val().trim();
        charges.alipay.name = $("#name").val().trim();
        charges.alipay.enable = $("input:radio:checked").val();
        charges.alipay.min = $("#min").val();
        charges.alipay.max = $("#max").val();
        startLoading();
        CMD.modify_group(GroupUtil.group.id, {
            charges: JSON.stringify(charges),
        }, function() {
            stopLoading();
            alert2("保存成功。");
        });
    });

    $("input.qrcode").change(function() {
        var data = new FormData();
        var file = $("input.qrcode")[0].files[0];
        if (file.size > 80 * 1024) {
            alert2("二维码大小必须小于80K！");
            return;
        }
        data.append("eddy.message.image", $("input.qrcode")[0].files[0]);
        
        startLoading();
        CMD.upload(data, null, function(r) {
            stopLoading();
            $("img.qrcode").attr("src", r);
            charges.alipay.qrcode = r;
            alert2("二维码上传完成，请点击保存后生效。");
        });
    });
</script>